// JavaScript Document
function getsubService(fid) {
    $.ajax({
        url: U('admin/ServiceCate/getServiceCategory') + '&item_id=' + fid,
        cache: false,
        success: function(html) {
            $("#service_item").empty();
            $("#service_cate").append(html);
        }
    });
}

function getUserServiceInfo(sid, uid) {
    $.ajax({
        url: U('admin/user/getUserServiceInfo') + '&service_id=' + sid + '&uid=' + uid,
        cache: false,
        success: function(html) {
            if ($("#service_cate").length) {
                $("#service_cate").remove();
            }
            if ($("#addon").length) {
                $("#addon").remove();
            }
             if ($("#require").length) {
                $("#require").remove();
            }
            if ($("#price").length) {
                $("#price").remove();
            }
            $("#service_item").after(html);
//            alert(html);
//            $("#service_item").append(jQuery.trim(html));
        }
    });
}
function getAllServiceCate(sid) {
    $.ajax({
        url: U('admin/ServiceCate/getAllServiceCate') + '&item_id=' + sid,
        cache: false,
        success: function(html) {
            if (html) {
                $("#allCate").empty();
                $("#allCate").append(html);
            }

        }
    });
}

function getSubItem(item_id, service_id, self) {
    $.get(U('home/Service/ajaxGetSubItem'), {item_id: item_id, service_id: service_id}, function(msg) {
        if (msg.type == 1) {
            $(self).next().nextAll().remove();
            $(self).parent('dd').nextAll().remove();
            $(self).parent('dd').append(msg.content);
        }else{
            $(self).next().nextAll().remove();
            $(self).parent('dd').nextAll().remove();
            $(self).parent('dd').after(msg.content);
        }
        if(msg.service_id){
            $("#service_id").val(msg.service_id);
            $("#serviceForm").attr("action",U('home/Service/doEditService'));
        }else{
            $("#service_id").val(0);
            $("#serviceForm").attr("action",U('home/Service/doRegisterService'));
        }
        $('input').customInput();
        $(".dept_select").chosen();
        $(".dept_select").trigger("liszt:updated");
        $("#serviceForm").Validform().config();
    });
}

function getAllServiceCateByItem(id, sid) {
    var param = "&item_id=" + id;
    if (sid) {
        param += "&service_id=" + sid;
    }
    $.ajax({
        url: U('home/Service/getAllServiceCateByItem') + param,
        cache: false,
        success: function(html) {
            var obj = jQuery.parseJSON(jQuery.trim(html));
            if ($(".service_cate").length) {
                $(".service_cate").remove();
            }
            if ($(".addon").length) {
                $(".addon").remove();
            }
            if (obj.service_cate) {
//              $("#service_cate").empty();
                $(".s_experience").remove();
                $(".desc").remove();
                $("#service_info").append(obj.service_cate);
                $(".experience").chosen();
//                $(".experience").trigger("liszt:updated");

            }
            if (obj.addon) {
                $("#service_info").append(obj.addon);
            }
            $('input').customInput();
            $("#item_id").val(id);
        }
    });
}
